package com.bsoft.webflux.controller;

import com.bsoft.webflux.pojo.UserVO;
import org.reactivestreams.Publisher;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: hdh
 * @Desc:
 * @create: 2024-03-13 09:57
 **/

@RestController
@RequestMapping("/users")
public class UserController {
    @GetMapping("/list")
    public Flux<UserVO> list(){
        //查询列表
        List<UserVO> result = new ArrayList<>();

        result.add(new UserVO(1,"yudaoyunma"));
        result.add(new UserVO(2,"woshiyutou"));
        result.add(new UserVO(3,"chifanshuijiao"));

        return  Flux.fromIterable(result);

    }
    //获得指定用户编号的id
     @GetMapping("/get")
    public Mono<UserVO> get(@RequestParam("id") Integer id){
        //查询用户
        UserVO user = new UserVO(id,"username"+id);
        //返回
        return Mono.just(user);

    }
     //添加
    @PostMapping("add")
    public Mono<Integer> add(@RequestBody Publisher<UserVO> addDTO){
        Integer returnId =1;
        return  Mono.just(returnId);
    }
    @PostMapping("/update")
    public  Mono<Boolean> update(@RequestBody Publisher<UserVO> updateDTo){
        //更新记录
        Boolean success = true;

        return  Mono.just(success);
    }

    //删除指定的用户
    @PostMapping("/delete")
    public  Mono<Boolean> delete(@RequestParam("id") Integer id){
        //删除记录
        Boolean success = false;
        //返回成功
        return  Mono.just(success);
    }
}
